package com.bitejiuyeke.bitecommonmessage.config;


import com.aliyun.credentials.models.Config;
import com.aliyun.dypnsapi20170525.Client;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.aliyun.tea.*;

/**
 * 阿里云短信服务配置参数
 */
@Configuration
@RefreshScope
public class AliSmsConfig {

    @Value("${sms.aliyun.accessKeyId}")
    private String accessKeyId;

    @Value("${sms.aliyun.accessKeySecret}")
    private String accessKeySecret;

    @Value("${sms.aliyun.endpoint:}")
    private String endpoint;

    /**
     * 注册客户端
     * @return 发送短信请求的客户端
     * @throws Exception
     */
    @Bean("aliClient")
    public Client getClient() throws Exception {
        com.aliyun.credentials.Client credential = new com.aliyun.credentials.Client();
        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
                .setCredential(credential);
        config.setAccessKeyId(accessKeyId);
        config.setAccessKeySecret(accessKeySecret);
       /* config.setAccessKeyId("LTAI5tB4NxJLiBFzttr7V9w4");
        config.setAccessKeySecret("zhrBrsET81kfpUWqLTgAVwMCkYTIwA");*/
        // Endpoint 请参考 https://api.aliyun.com/product/Dypnsapi
        config.endpoint = endpoint;
        return new com.aliyun.dypnsapi20170525.Client(config);
    }

}
